﻿using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;

namespace CMS.Business
{
    [Serializable]
    public class BaseViewModel : ICloneable
    {
        public BaseViewModel()
        {
            IsNew = true;
            ObjectId = Guid.NewGuid();
        }

        public Guid ObjectId { get; set; }

        public bool IsNew { get; set; }

        public bool IsDirty { get; set; }

        public bool IsVirtualDeleted { get; set; }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, this);
            ms.Position = 0;
            object obj = bf.Deserialize(ms);
            ms.Close();
            return obj;
        }
    }
}
